//
//  ST_SweetRankViewController.swift
//  btvideo
//
//  Created by mac on 2020/7/15.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

class ST_SweetRankViewController: ST_BTLightBarViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title_nav_btn.setTitleForAllStates("亲密等级")
        
        self.view.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 44+statusBarHeight, left: 0, bottom: 0, right: 0))
        }
        
        request_data()
        
    }
    
    
    fileprivate func request_data(){
        
        JVrequest(PH.getIntimacyLevelApi, success: { (json) in
            
            self.data_array = json["data"].arrayValue.map { (itemJson) -> ST_SweetValueLevelModel in
            
                return ST_SweetValueLevelModel.init(fromJson: itemJson)
            }
            
            self.collectionView.reloadData()
            
        }) { (code, err) in
            
            self.toast(text: err)
        }
        
        
    }
    
    fileprivate var data_array = [ST_SweetValueLevelModel]()
    
    fileprivate lazy var layout:UICollectionViewFlowLayout = {
        let controlLayout = UICollectionViewFlowLayout()
        controlLayout.minimumLineSpacing = 0
        controlLayout.minimumInteritemSpacing = 0
        controlLayout.sectionInset = UIEdgeInsets.init(top: 0, left: 0, bottom: BTSafeAreaBottom + 10, right: 0)
        controlLayout.itemSize = CGSize.init(width: ScreenWidth, height: 60)
        return controlLayout
    }()
    
    fileprivate lazy var collectionView:UICollectionView = {
        let control = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: self.layout)
        control.delegate = self
        control.dataSource = self
        control.register(cellWithClass: SweetLevelItemView.self)
        
        if #available(iOS 11.0, *) {
            control.contentInsetAdjustmentBehavior = .never
        }
        control.backgroundColor = UIColor.white
        control.alwaysBounceVertical = true
      
        return control
    }()
}


extension ST_SweetRankViewController:UICollectionViewDelegate,UICollectionViewDataSource{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return data_array.count
        
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withClass: SweetLevelItemView.self, for: indexPath)
        
        cell.model = data_array[safe:indexPath.row]
        
        return cell
    }
    
    
    
    
    
}
